﻿using System;
using System.Drawing.Imaging;
using System.IO;

namespace TypedROBIN.Imaging
{
    public class Utils
    {
        public ImageCodecInfo GetImageCodec(string imageFilePath)
        {
            string imageMimeType = "image/jpeg";
            string ext = Path.GetExtension(imageFilePath).ToLowerInvariant();
            switch (ext)
            {
                case ".png":
                    imageMimeType = "image/png";
                    break;
                case ".bmp":
                case ".dib":
                    imageMimeType = "image/bmp";
                    break;
                case ".tif":
                case ".tiff":
                    imageMimeType = "image/tiff";
                    break;
                case ".gif":
                    imageMimeType = "image/gif";
                    break;
                default:
                    break;
            }

            ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
            ImageCodecInfo ici = null;
            foreach (ImageCodecInfo codec in codecs)
            {
                if (codec.MimeType == imageMimeType)
                    ici = codec;
            }
            return ici;
        }
    }
}
